<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.org/ui">


    <ui:define name="content">

        <h:panelGroup >
            <h:form  >
                <p:panel header="Manage Pharmacy Item" styleClass="alignTop verticalAndHorizontalCenteringLarge" >
                    <h:panelGrid id ="gpVeda" columns="2" >


                        <h:panelGrid id="gpSelect" columns="1" styleClass="alignTop" >
                            <p:panel  styleClass="alignTop" >
                                <h:panelGrid columns="1" id="gpSelectText" >
                                    <h:outputText value="Search By Name / Code / Barcode"/>
                                    <p:autoComplete id="lstSelect1"    value="#{ampController.current}" 
                                                    forceSelection="true"
                                                    style="min-width: 223px" completeMethod="#{ampController.completeAmp}" 
                                                    var="myItem" itemValue="#{myItem}" itemLabel="#{myItem.name}" >
                                        <p:column headerText="Item">
                                            <h:outputLabel value="#{myItem.name}" ></h:outputLabel>
                                        </p:column>
                                        <p:column headerText="Code">
                                            <h:outputLabel value="#{myItem.code}" ></h:outputLabel>
                                        </p:column>
                                        <p:column headerText="Barcode">
                                            <h:outputLabel value="#{myItem.barcode}" ></h:outputLabel>
                                        </p:column>
                                        <f:ajax event="itemSelect" render="gpDetail" execute="lstSelect1" >
                                        </f:ajax>
                                    </p:autoComplete>


                                    <p:commandButton id="btnRefresh" value="Refresh" style="display:none;" ></p:commandButton>
                                    <p:defaultCommand target="btnRefresh" ></p:defaultCommand>


                                </h:panelGrid>
                                <h:panelGrid id="gpSelectButtons" columns="3"  >
                                    <p:commandButton ajax="false" id="btnAdd" value="Add New Item" action="#{ampController.prepareAdd()}" styleClass="buttons" >

                                    </p:commandButton>
                                    <p:commandButton ajax="false" id="btnDelete" 
                                                     onclick="if (!confirm('Are you sure you want to delete this record?'))
                                                                 return false;" action="#{ampController.delete()}"  
                                                     value="Delete Selected Item"  >

                                    </p:commandButton>
                                </h:panelGrid>
                            </p:panel>
                        </h:panelGrid  >

                        <p:panel>
                            <f:facet name="header" >
                                <h:outputText value="Item Details" >
                                </h:outputText>
                                <p:spacer width="30" height="1" ></p:spacer>
                                <p:commandButton id="btnSave" value="Save" ajax="false" 
                                                 action="#{ampController.saveSelected}" styleClass="buttons">
                                </p:commandButton>
                            </f:facet>
                            <h:panelGrid id="gpDetail" columns="1">
                                <h:panelGrid id="gpDetailText">

                                    <h:panelGrid columns="3">
                                        <h:outputText  value="Name" ></h:outputText>
                                        <p:inputText autocomplete="off" id="txtName"  value="#{ampController.current.name}" styleClass="longText"  />
                                        <h:outputText value="" ></h:outputText>

                                        <h:outputText  value="Code" ></h:outputText>
                                        <p:inputText id="code" autocomplete="off"  value="#{ampController.current.code}" disabled="true" ></p:inputText>
                                        <h:outputText value="" ></h:outputText>

                                        <h:outputText  value="Department Type" ></h:outputText>
                                        <h:outputText  value="#{ampController.current.departmentType}" ></h:outputText>
                                        <h:outputText value="" ></h:outputText>
                                        
                                        <h:outputText  value="Bar Code" ></h:outputText>
                                        <p:inputText autocomplete="off"  value="#{ampController.current.barcode}"  ></p:inputText>
                                        <h:outputText value="" ></h:outputText>

                                        <h:outputText  value="Manufacturer" ></h:outputText>
                                        <p:autoComplete  completeMethod="#{manufacturerController.completeManu}"
                                                         var="pta" itemLabel="#{pta.name}" itemValue="#{pta}"
                                                         forceSelection="true" 
                                                         value="#{ampController.current.institution}" ></p:autoComplete>
                                        <h:outputText value=""></h:outputText>

                                        <h:outputLabel value="Category"/>
                                        <p:autoComplete  value="#{ampController.current.category}" 
                                                         forceSelection="true" converter="categoryConverter"
                                                         completeMethod="#{pharmaceuticalItemCategoryController.completeCategory}" 
                                                         var="vt" itemLabel="#{vt.name}" itemValue="#{vt}" >
                                            <f:ajax event="itemSelect" render="code" execute="@this"  listener="#{ampController.listnerCategorySelect()}"/>
                                        </p:autoComplete>      
                                        <h:outputText value="" ></h:outputText>

                                        <h:outputText  value="Product" ></h:outputText>
                                        <p:autoComplete  converter="vmp" 
                                                         completeMethod="#{vmpController.completeVmp}"
                                                         var="pta" itemLabel="#{pta.name}" itemValue="#{pta}" forceSelection="true" value="#{ampController.current.vmp}" ></p:autoComplete>
                                        
                                        <h:outputLabel/>
                                        <h:outputText  value="Discount Allowed" ></h:outputText>
                                        <h:selectBooleanCheckbox value="#{ampController.current.discountAllowed}" />
                                        
                                        <p:commandLink id="btnAddVmp" 
                                                         value="Create New Product" 
                                                         action="/pharmacy/pharmacy_vmp"/>  





                                    </h:panelGrid>
                                    <p:dialog id="dlgVmp" widgetVar="dlgVmp"  >

                                        <p:panelGrid columns="2">
                                            <h:outputLabel value="Generic Name" ></h:outputLabel>
                                            <p:autoComplete converter="vtm" value="#{ampController.addingVtmInVmp.vtm}"
                                                            forceSelection="true"
                                                            completeMethod="#{vtmController.completeVtm}" var="vt"
                                                            itemLabel="#{vt.name}" itemValue="#{vt}" >
                                            </p:autoComplete>
                                            <h:outputLabel value="Strength" />                                                    
                                            <p:inputText autocomplete="off" value="#{ampController.addingVtmInVmp.strength}" ></p:inputText>
                                            <h:outputLabel value="Strength Unit" />                                                    
                                            <p:selectOneMenu value="#{ampController.addingVtmInVmp.strengthUnit}">
                                                <f:selectItem itemLabel="Select a generic name" ></f:selectItem>
                                                <f:selectItems value="#{measurementUnitController.items}" var="m" itemValue="#{m}" itemLabel="#{m.name}"/>
                                            </p:selectOneMenu>  

                                            <h:outputLabel value="Type" ></h:outputLabel>
                                            <p:autoComplete value="#{ampController.currentVmp.category}"
                                                            forceSelection="true"
                                                            completeMethod="#{pharmaceuticalItemTypeController.completeCategory}" 
                                                            var="vt" itemLabel="#{vt.name}" itemValue="#{vt}" >
                                            </p:autoComplete>


                                            <h:outputLabel value="Name" ></h:outputLabel>
                                            <p:outputLabel value="#{ampController.currentVmp.name}" />

                                        </p:panelGrid>


                                    </p:dialog>




                                </h:panelGrid>
                            </h:panelGrid>
                        </p:panel>
                    </h:panelGrid>
                </p:panel>
            </h:form>

        </h:panelGroup>

    </ui:define>

</ui:composition>
